vec2 fixUV(vec2 cood){
  return 3.*(2.*cood.xy-iResolution.xy)/min(iResolution.x,iResolution.y);
}

vec3 Grid(vec2 uv){
  vec3 color=vec3(0.);
  vec2 grid=floor(mod(uv,2.));
  if(grid.x==grid.y)color=vec3(.6);
  // 换个方式画x，y轴
  // color=mix(color,vec3(0.,1.,0.),smoothstep(1.1*fwidth(uv.x),fwidth(uv.x),abs(uv.x)));
  // color=mix(color,vec3(1.,0.,0.),smoothstep(1.1*fwidth(uv.y),fwidth(uv.y),abs(uv.y)));
  return color;
}

// 搞不懂这里画斜线的原理
float segment(vec2 p,vec2 a,vec2 b,float w){
  float f=0.;
  vec2 ba=b-a;
  vec2 pa=p-a;
  float proj=clamp(dot(pa,ba)/dot(ba,ba),0.,1.);
  float d=length(proj*ba-pa);
  if(d<=w){
    f=1.;
  }
  return f;
}

void mainImage(out vec4 fragColor,in vec2 fragCoord){
  vec2 vUv=fixUV(fragCoord);
  vec3 color=Grid(vUv);
  // 给斜线混入黄色
  color=mix(color,vec3(1.,1.,0.),segment(vUv,vec2(1.,2.),vec2(-2.,-2.),fwidth(vUv.x)));
  fragColor=vec4(color,1);
}